package com.drinks.yiniang.adapter.user.message;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseMultiItemQuickRCVAdapter;
import com.drinks.yiniang.entity.message.MessageJson;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.ui.widget.image.CircleImageView;
import com.hansen.library.ui.widget.image.RatioRoundImageView;
import com.hansen.library.utils.ScreenSizeUtils;

import java.util.List;

import static com.drinks.yiniang.entity.message.MessageJson.ITEM_TYPE_MSG_NOTICE;
import static com.drinks.yiniang.entity.message.MessageJson.ITEM_TYPE_MSG_TIPS;

/**
 * 通知消息列表adapter
 *
 * @author han
 * @date 2019/8/30
 */
public class NoticeMessageAdapter extends BaseMultiItemQuickRCVAdapter<MessageJson.MessageList, BaseViewHolder> {

    private SpannableStringBuilder mBuilder;

    private int sp25;

    public NoticeMessageAdapter(Context mContext, @Nullable List<MessageJson.MessageList> data) {
        super(data);

        addItemType(ITEM_TYPE_MSG_NOTICE, R.layout.item_notice_message);
        addItemType(ITEM_TYPE_MSG_TIPS, R.layout.item_notice_message_tips);

        mBuilder = new SpannableStringBuilder();

        sp25 = ScreenSizeUtils.sp2px(25);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageJson.MessageList item) {
        switch (helper.getItemViewType()) {
            case ITEM_TYPE_MSG_NOTICE://通知消息
                GlideUtils.loadAvatar(mContext, (CircleImageView) helper.getView(R.id.iv_community_msg_avatar), item.getFrom_avatar());
                GlideUtils.loadSquareImage(mContext, (RatioRoundImageView) helper.getView(R.id.iv_community_msg_cover), item.getCover_url());
                helper.setText(R.id.tv_community_msg_nickname, item.getFrom_username());
                helper.setText(R.id.tv_community_msg_tips, item.getTitle());
                helper.setText(R.id.tv_community_msg_info, item.getContent());
                helper.setText(R.id.tv_community_msg_time, item.getCreate_time());
                break;
            case ITEM_TYPE_MSG_TIPS://通知消息简版
                GlideUtils.loadAvatar(mContext, (CircleImageView) helper.getView(R.id.iv_community_msg_tips_avatar), item.getFrom_avatar());
                helper.setText(R.id.tv_community_msg_nickname, item.getFrom_username());
                helper.setText(R.id.tv_community_msg_tips_tips, item.getTitle());
                break;
            default:
                break;
        }
    }
}
